#include "GCursor.h"
#include "GWindow.h"

#include "../../Foundation/GUtilities/GLog.h"
#include "../../Foundation/GUtilities/GError.h"

namespace GEngine
{
	bool GCursor::GetVisible()
	{
		return Visible;
	}

	bool GCursor::GetPosition(GWindow* Window, GInt32& PosX, GInt32& PosY)
	{
		GUtil::GError::DebugCheck(Window == NULL, "NULL Pointer.");
		GUtil::GError::DebugCheck(Window->GetHandle() == NULL, "Window is not creted.");

		GInt32 ClientX, ClientY;
		Window->GetPosition(ClientX, ClientY);

		GInt32 CursorX, CursorY;
		GetPosition(CursorX, CursorY);

		PosX = ClientX - CursorX;
		PosY = ClientY - CursorY;

		return true;
	}

	bool GCursor::CollisionCheck(GWindow* Window)
	{
		GInt32 ClientX, ClientY;
		Window->GetPosition(ClientX, ClientY);

		GInt32 ClientWidth, ClientHeight;
		Window->GetSize(ClientWidth, ClientHeight);

		GInt32 CursorX, CursorY;
		GetPosition(CursorX, CursorY);

		bool VerticalCheck = (CursorY > ClientY) && (CursorY < (ClientY + ClientHeight));
		bool HorizontalCheck = (CursorX > ClientX) && (CursorX < (ClientX + ClientWidth));

		return VerticalCheck && HorizontalCheck;
	}

	GWindow* GCursor::GetLockWindow()
	{
		return LockWindow;
	}

	bool GCursor::Visible = false;
	GWindow* GCursor::LockWindow = NULL;

	GCursor::GCursor()
	{
	}

	GCursor::~GCursor()
	{
	}

}